﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell;
using System.Windows;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Tests.Integration.Instruments
{
    public class WindowPaneWrapper<TWindowPane> : IWindowPaneWrapper
        where TWindowPane : ToolWindowPane
    {
        private TWindowPane windowPane;

        private FrameworkElement content;


        public WindowPaneWrapper(TWindowPane windowPane)
        {
            this.windowPane = windowPane;
            content = windowPane.Content as FrameworkElement;
        }

        public TElement Get<TElement>(string name)
            where TElement : FrameworkElement
        {
            return content.FindName(name) as TElement;
        }

        public void Close()
        {
            var frame = (IVsWindowFrame)windowPane.Frame;
            ErrorHandler.ThrowOnFailure(frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave));
        }
    }
}
